package com.jsjvm.client.execution.objrepr.js;

import com.google.gwt.core.client.JavaScriptObject;
import com.jsjvm.client.classparser.JClass;
import com.jsjvm.client.classparser.JMember.JMethod;
import com.jsjvm.client.classparser.jconstants.JMemberConstant;
import com.jsjvm.client.execution.JClassLoader.JClassNotLoadedException;
import com.jsjvm.client.execution.objrepr.ObjectRepr;

/**
 * 
 * GWT's representation of objects. 
 * 
 * @author ctalau
 */
// TODO: to be implemented in step 2
public class NativeObjectRepr extends JavaScriptObject implements ObjectRepr {
	protected NativeObjectRepr() {
	}

	public final native static NativeObjectRepr newNativeObjectRepr(JClass jc) /*-{
		var ret = {
			$class : jc
		}
		return ret;
	}-*/;

	@Override
	public final native Object getField(JMemberConstant fld) /*-{
		return this[name];
	}-*/;

	@Override
	public final native void putField(JMemberConstant fld, Object value) /*-{
		this[name] = val;
	}-*/;

	@Override
	public final native JClass getJClass() /*-{
		return this.$class;
	}-*/;

	@Override
	public final native JMethod dispatchMethod(JMemberConstant cm) /*-{
		return this[name](args);
	}-*/;

	@Override
	public final native JMethod dispatchSuperMethod(JMemberConstant cm) /*-{
		return this[name](args);
	}-*/;

	@Override
	public final native JMethod dispatchNonVirtualMethod(JMemberConstant cm)
			throws JClassNotLoadedException
	/*-{
		return this[name](args);
	}-*/;

	
	int id = -1;
	@Override
	public int getID() {
		return id;
	}

	@Override
	public void setID(int id) {
		this.id = id;
	}

}
